﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace Toolkit.Web.Mvc.Validation
{
    public class EmailAddressModelValidator : DataAnnotationsModelValidator<EmailAddressAttribute>
    {
        public EmailAddressModelValidator(ModelMetadata metadata, ControllerContext controllerContext, EmailAddressAttribute attribute)
            : base(metadata, controllerContext, attribute)
        {
        }

        public override IEnumerable<ModelClientValidationRule> GetClientValidationRules()
        {
            ModelClientValidationRule rule = new ModelClientValidationRule
            {
                ValidationType = "emailAddress",
                ErrorMessage = Attribute.FormatErrorMessage(Metadata.PropertyName),
            };

            return new[] { rule };
        }
    }
}
